package com.jiandan.business.service;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.jiandan.base.persistence.DynamicSpecifications;
import com.jiandan.base.persistence.SearchFilter;
import com.jiandan.base.persistence.SearchFilter.Operator;
import com.jiandan.base.utils.CollectionsUtil;
import com.jiandan.business.entity.Staff;
import com.jiandan.business.repository.StaffDao;

@Service
@Transactional(readOnly=true)
public class StaffServiceImpl implements StaffService{
	
	private static final Logger logger = Logger.getLogger(StaffServiceImpl.class);
	
	@Autowired
	private StaffDao staffDao;
	
	/**
	 * 验证操作员用户名密码.
	 *
	 * @param operator the operator
	 * @return true, if valid operator
	 */
	public Boolean validStaff(Staff staff){
		String name = staff.getName();
		String password = staff.getPassword();
		SearchFilter nameFilter = new SearchFilter("name", Operator.EQ, name);
		SearchFilter passwordFilter = new SearchFilter("password", Operator.EQ, password);
		List<Staff> staffList = staffDao.findAll(DynamicSpecifications.bySearchFilter(Lists.newArrayList(nameFilter, passwordFilter), Staff.class));
		return (CollectionsUtil.isNotEmpty(staffList) && staffList.size() == 1);
	}

}
